package com.drinks.yiniang.adapter.listview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.drinks.yiniang.R;
import com.drinks.yiniang.entity.goods.RefundGoodsJson;
import com.drinks.yiniang.utils.GlideUtils;
import com.hansen.library.ui.widget.image.RatioRoundImageView;
import com.hansen.library.utils.CommonUtils;
import com.hansen.library.utils.StringUtils;

import java.util.List;

/**
 * 酒类分析 adapter
 *
 * Created by han on 2019/6/27 0027.
 */

public class RefundGoodsListAdapter extends BaseAdapter {
    private Context mContext;

    private List<RefundGoodsJson.RefundGoodsList> mList;
    private RefundGoodsJson.RefundGoodsList mGoodsData;

    private LayoutInflater inflater;

    private StringBuilder mBuilder;

    public RefundGoodsListAdapter(Context mContext, List<RefundGoodsJson.RefundGoodsList> mList) {
        this.mContext = mContext;
        this.mList = mList;

        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return CommonUtils.getListSize(mList);
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder mHolder = null;

        if (convertView == null) {
            mHolder = new ViewHolder();

            convertView = inflater.inflate(R.layout.item_refund_goods, null);

            mHolder.iv_refund_goods_cover = convertView.findViewById(R.id.iv_refund_goods_cover);
            mHolder.tv_refund_goods_name = convertView.findViewById(R.id.tv_refund_goods_name);
            mHolder.tv_refund_goods_price = convertView.findViewById(R.id.tv_refund_goods_price);
            mHolder.tv_refund_goods_slogan = convertView.findViewById(R.id.tv_refund_goods_slogan);
            mHolder.tv_refund_goods_attrs = convertView.findViewById(R.id.tv_refund_goods_attrs);
            mHolder.tv_refund_goods_num = convertView.findViewById(R.id.tv_refund_goods_num);

            convertView.setTag(mHolder);
        } else {
            mHolder = (ViewHolder) convertView.getTag();
        }

        mGoodsData = mList.get(position);

        //封面
        GlideUtils.loadSquareImage(mContext, mHolder.iv_refund_goods_cover, mGoodsData.getCover_url());
        //名称
        mHolder.tv_refund_goods_name.setText(mGoodsData.getGoods_name());
        //价格
        mBuilder = new StringBuilder("¥");
        mBuilder.append(StringUtils.getNullEmptyConvert__(mGoodsData.getPrice()));
        mHolder.tv_refund_goods_price.setText(mBuilder);
        //推荐语
        mHolder.tv_refund_goods_slogan.setText(mGoodsData.getRecommend_reason());
        //容积
        mBuilder = new StringBuilder();
        mBuilder.append(StringUtils.judgeGreaterNumber(mGoodsData.getSingle_capacity(), 0f) ? mGoodsData.getSingle_capacity() : "");
        mBuilder.append(mBuilder.length() > 0 ? "ml" : "");
        mHolder.tv_refund_goods_attrs.setText(mBuilder);
        //数量
        mBuilder = new StringBuilder("x");
        mBuilder.append(StringUtils.getNullEmptyConvert__(mGoodsData.getNum()));
        mHolder.tv_refund_goods_num.setText(mBuilder);

        return convertView;
    }

    class ViewHolder {
        //封面
        RatioRoundImageView iv_refund_goods_cover;
        //商品名称
        TextView tv_refund_goods_name;
        //价格
        TextView tv_refund_goods_price;
        //推荐语
        TextView tv_refund_goods_slogan;
        //属性
        TextView tv_refund_goods_attrs;
        //数量
        TextView tv_refund_goods_num;
    }
}
